#define _CRT_SECURE_NO_WARNINGS

//https ://leetcode.cn/problems/missing-number-lcci/
int missingNumber(int* nums, int numsSize) {
    int add = 0;
    int i = 0;
    for (i = 0; i <= numsSize; i++)
    {
        add += i;
    }
    for (i = 0; i < numsSize; i++)
    {
        add -= nums[i];
    }
    return add;
}


// https://leetcode.cn/problems/set-mismatch/
int* findErrorNums(int* nums, int numsSize, int* returnSize) {
    *returnSize = 2;
    int* same = (int*)malloc(sizeof(int) * numsSize);
    assert(same);
    memset(same, 0, numsSize * 4);
    for (int i = 0; i < numsSize; i++)
    {
        same[nums[i] - 1]++;
    }
    int* tmp = (int*)malloc(8);
    for (int i = 0; i < numsSize; i++)
    {
        if (same[i] == 0)
        {
            tmp[1] = i + 1;
        }
        if (same[i] == 2)
        {
            tmp[0] = i + 1;
        }
    }
    return tmp;
}
